package com.tech.ioc;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.util.Assert;

/**
 * @Description: spring上下文容器
 * @Author: zl
 * @Date: 2019/5/22 23:14
 */
public class ApplicationContextExam {


    /**
     * FileSystemXmlApplicationContext:该容器从 XML 文件中加载已被定义的 bean。在这里，你需要提供给构造器 XML 文件的完整路径。
     */
    @Test
    public void fileSystemApplicationContextTest() {
        ApplicationContext context = new FileSystemXmlApplicationContext("D:\\workspace\\ideal_work_local\\java-enterprise-application\\tech-learning\\tech-learning-spring\\src\\main\\resources\\applicationContextExam.xml");
        HelloWorldBean bean = (HelloWorldBean) context.getBean("helloword");
        bean.getMessage();
    }


    /**
     * ClassPathXmlApplicationContext：容器会从 CLASSPATH 中搜索 bean 配置文件。
     */
    @Test
    public void classPathXmlApplicationContextTest(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContextExam.xml");
        HelloWorldBean bean = (HelloWorldBean) context.getBean("helloword");
        bean.getMessage();
    }

    /**
     * WebXmlApplicationContext: 该容器会在一个web容器的范围类加载xml文件内已经被定义的bean
     * */
    @Test
    public void webXmlApplicationContextTest(){
       // WebXmlApplicationContext context = new WebXmlApplicationContext();
    }

    public static void main(String[] args) {

        Assert.noNullElements(new String[]{null}, "Config locations must not be null");
        System.out.println("--");
    }
}

